<!--
 * @Author: lining
 * @Date: 2022-11-22 15:55:03
 * @Description: 流程起草
-->
<template>
  <div>
    <div class="">
    </div>
    <div class="draft-list">
      <template>
        <!-- <el-row>
          <el-col :span="24">
            <jdf-common-input
              v-model="searchable"
              el-type="select"
              :options="templateCodes"
              filterable
              clearable
            >
            </jdf-common-input>
          </el-col>
        </el-row> -->
        <el-row>
          <el-col  v-for="(template, index) in draftList" :key="index" :span="8">
            <ul>
              <li>
                <el-link @click="draft(template)" type="info">{{ template.resourceDesc }}</el-link>
              </li>
            </ul>
          </el-col>
        </el-row>
      </template>
    </div>
    <jdf-select-identity
      ref="selectIdentity"
      v-model="identityId"
      :identity-list="identityList"
      @choose="chooseDraft"
    ></jdf-select-identity>
  </div>
</template>

<script>
import { UserIdentityService } from 'jdf-jssdk';
import { mapGetters } from 'vuex';
import store from '@/vuex/store';
import { bizServiceURL } from '@/api/utils/constants';
import draftMixins from '@/mixins/draftMixins';

export default {
  mixins: [draftMixins],
  data() {
    return {
      // draftList: [],
      identityId: '',
      identityList: [],
      template: null,
      resouceCode: this.$route.name,
      searchable: '',
    };
  },
  computed: {
    ...mapGetters(['loginName', 'allMenus']),
    /**
     * 获取起草列表
     */
    draftList() {
      return store.state.menu.allMenus.filter((v) => v.parentCode === this.resouceCode);
    },
    /**
     * 可搜索列表
     */
    templateCodes() {
      const { allMenus } = store.state.menu;
      return allMenus?.filter(v => v?.extendConfig?.includes('templateCode')).map(t => ({
        label: t.resourceDesc,
        value: t.resourceCode
      }));
    }
  },
  methods: {
    /**
     * 点击流程模板进行起草
     * @param {Object} template 流程模板信息
     */
    async draft(template) {
      this.template = template;
      // 获取当前人身份列表
      const identityList = await new UserIdentityService(bizServiceURL).getByLoginName(this.loginName);
      if (identityList.length === 1) {
        const [{ id }] = identityList;
        this.identityId = id;
        this.draftProcess(template.resourceCode, template.resourceDesc, this.identityId, {}, '/process-form-oa');
      } else {
        this.identityList = identityList;
        this.$refs.selectIdentity.show();
      }
    },
    chooseDraft() {
      const { template } = this;
      this.draftProcess(template.resourceCode, template.resourceDesc, this.identityId, {}, '/process-form-oa');
    },
  }
};
</script>

<style lang="scss" scoped>
.draft-list {
  padding: 20px;
  ul {
    padding-left: 10px;
    li {
      list-style: disc;
      color: #a6a9ad;
    }
  }
}

</style>
